package com.mapper;

import com.bean.ClassBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ClazzMapperByAnnotation {

    @Select("select * from t_clazz")
    public List<ClassBean> getAllClazz();

    @Insert("insert into t_clazz (cname) values (#{cname})")
    public int addClazz(ClassBean classBean);

    @Delete("delete from t_clazz where id=#{id}")
    public int delClazzById(Integer id);

    @Update("update t_clazz set cname = #{cname} where id=#{id}")
    public int modifyClazz(ClassBean classBean);

    @Select("select * from t_clazz where id=#{id}")
    public ClassBean getClazzById(Integer id);

    @Select("select * from t_clazz where id=#{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "cname",property = "cname"),
            @Result(column = "id",property = "students",
                    many = @Many(select = "com.mapper.StudentMapperByAnnotation.findStuForClazzById")),
    })
    public ClassBean getStuInClazzBycid(Integer id);
}
